package com.weipu.common.facade.model;

import java.io.Serializable;

import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

import com.weipu.common.constants.ServerConstant;

/** 
 * @Description  目录model
 * @version [版本号, 2012-10-29]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 * 
 * @author yw66009
 */

public class CatelogModel implements Parcelable
{
    /** 
     * @Fields serialVersionUID : 序列版本号
     */
    private static final long serialVersionUID = 7972608964433196433L;
    
    /**
     * 目录id
     */
    private int browseID = -1;
    
    /**
     * 父目录id
     */
    private String parentId;
    
    /**
     * 目录图标默认id
     */
    private int id;
    
    /**
     * 目录图标高亮id
     */
    private int id_hl;
    
    /**
     * 目录名称
     */
    private String shortName;
    
    /**
     * (本地)栏目数据更新时间，用于本地数据缓存，单位：毫秒
     */
    public long cacheUpdateTime;
    
    /**
     * @描述：用户ID
     */
    public long customerID;
    
    public boolean isShow;
    
    
    
    public boolean isShow() {
		return isShow;
	}

	public void setShow(boolean isShow) {
		this.isShow = isShow;
	}

	public long getCustomerID() {
		return customerID;
	}

	public void setCustomerID(long customerID) {
		this.customerID = customerID;
	}

	public long getCacheUpdateTime()
    {
        return cacheUpdateTime;
    }
    
    public void setCacheUpdateTime(long cacheUpdateTime)
    {
        this.cacheUpdateTime = cacheUpdateTime;
    }
    
    public int getBrowseID()
    {
        return browseID;
    }
    
    public void setBrowseID(int browseID)
    {
        this.browseID = browseID;
    }
    
    public String getParentId()
    {
        return parentId;
    }
    
    public void setParentId(String parentId)
    {
        this.parentId = parentId;
    }
    
    public int getId_hl()
    {
        return id_hl;
    }
    
    public void setId_hl(int id_hl)
    {
        this.id_hl = id_hl;
    }
    
    public int getId()
    {
        return id;
    }
    
    public void setId(int id)
    {
        this.id = id;
    }
    
    public String getShortName()
    {
        return shortName;
    }

    @Override
    public String toString() {
        return "CatelogModel{" +
                "browseID=" + browseID +
                ", parentId='" + parentId + '\'' +
                ", id=" + id +
                ", id_hl=" + id_hl +
                ", shortName='" + shortName + '\'' +
                ", cacheUpdateTime=" + cacheUpdateTime +
                ", customerID=" + customerID +
                ", isShow=" + isShow +
                '}';
    }

    public void setShortName(String shortName)
    {
        this.shortName = shortName;
    }
    
    /**
     * 从json格式的CatelogModel对象 转换 为 父母录CatelogModel 对象
     * @param json格式的CatelogModel对象  = {ID:3345,ShortName:'computer',Icon:'http://'}
     * @return CatelogModel对象
     */
    public static CatelogModel json2TopCategories(JSONObject json)
    {
        if (null == json)
        {
            return null;
        }
        CatelogModel model = new CatelogModel();
        
        model.setBrowseID(json.optInt(ServerConstant.Catelog.CONSTANT_ID));
        if (json.optString(ServerConstant.Catelog.CONSTANT_NEWHEADLINE) != JSONObject.NULL
            && !json.isNull(ServerConstant.Catelog.CONSTANT_NEWHEADLINE))
        {
            model.setShortName(json.optString(ServerConstant.Catelog.CONSTANT_NEWHEADLINE));
        }
        model.setCacheUpdateTime(System.currentTimeMillis());
        
        return model;
    }
    
    public static CatelogModel json2ChildCategories(JSONObject json)
    {
        if (null == json)
        {
            return null;
        }
        CatelogModel model = new CatelogModel();
        
        model.setBrowseID(json.optInt(ServerConstant.Catelog.CONSTANT_ID));
        if (json.optString(ServerConstant.Catelog.CONSTANT_NEWHEADLINE) != JSONObject.NULL
            && !json.isNull(ServerConstant.Catelog.CONSTANT_NEWHEADLINE))
        {
            model.setShortName(json.optString(ServerConstant.Catelog.CONSTANT_NEWHEADLINE));
        }
        return model;
    }

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(browseID);
		dest.writeString(parentId);
		dest.writeInt(id);
		dest.writeInt(id_hl);
		dest.writeString(shortName);
		dest.writeLong(cacheUpdateTime);
		dest.writeLong(customerID);
		dest.writeInt(isShow?0:1);
	}
	
	public CatelogModel(){}
	
	public CatelogModel(Parcel source){
		browseID = source.readInt();
		parentId = source.readString();
		id = source.readInt();
		id_hl = source.readInt();
		shortName = source.readString();
		cacheUpdateTime = source.readLong();
		customerID = source.readLong();
		int readInt = source.readInt();
		if(readInt == 0){
			isShow = true;
		}else{
			isShow = false;
		}
	}
	
	public static final Parcelable.Creator<CatelogModel> CREATOR = new Creator<CatelogModel>() {
		
		@Override
		public CatelogModel[] newArray(int size) {
			// TODO Auto-generated method stub
			return new CatelogModel[size];
		}
		
		@Override
		public CatelogModel createFromParcel(Parcel source) {
			// TODO Auto-generated method stub
			return new CatelogModel(source);
		}
	};
}
